<?php
//phpinfo();
//var_dump(get_defined_constants());
?>
<style>
.OK{
color: Green;
}
.Warning{
color: GoldenRod;
}
.Error{
color: Red;
}
ul, li{
	padding-top: 0px;
	padding-bottom: 0px;
	margin: 0px;
}
</style>
<?php if($_SERVER['REQUEST_METHOD'] === 'POST'): ?>
<?php header('Location: ?step=configuration') ; ?>
<?php else: ?>
<h1>Sprawdzenie wymagań</h1>

Wersja PHP: <?php echo check('php', '5.2.4'); ?>
<br />

mod_rewrite
<br />
<h2>PHP Modules</h2>
php_FileInfo: <?php echo check('fileinfo'); ?>
<br />
php_FTP: <?php echo check('ftp'); ?>
<br />
php_GD: <?php echo check('gd'); ?>
<br />
php_Libxml: <?php echo check('libxml', '2', 'error'); ?>
<br />
php_Session: <?php echo check('session', null, 'error'); ?>
<br />
php_XSL: <?php echo check('xsl'); ?>
<br />

<h2>Files permissions</h2>


<h2>Databases</h2>
php_SQLite: <?php echo check('sqlite3'); ?>
<?php
echo (checkB('SQLite')||checkB('sqlite3'))?'<span class="ok"><ul>':'<br />';
echo checkB('SQLite')?'<li>'.getV('SQLite').' - OK</li>':'';
echo checkB('sqlite3')?'<li>'.getV('sqlite3').' - OK</li>':'';
echo '</ul></span>' ?>
php_MySQL: <?php echo check('mysql'); ?>
<br />
php_MySQLi: <?php echo check('mysqli'); ?>
<br />
php_PostgreSQL: <?php echo check('pgsql'); ?>
<br />

<form method="post" enctype="text/plain">
	<input type="submit" value="Dalej" />
</form>
<?php endif; ?>
<?php
$data = array();
function check($add, $version = null, $type = 'warning'){
	global $data;
	if(!in_array($type, array('warning','error'))) $type = 'warning';
	if($version == null){
		$i = checkB($add);
		return ($i === True)?'<span class="ok">OK</span>':'<span class="'.$type.'">'.ucwords(strtolower($type)).'!</span>';
	}else{
		$i = checkV($add, $version);
		return ($i === True)?'<span class="ok">'.getV($add).' - OK</span>':'<span class="'.$type.'">'.getV($add).' '.ucwords(strtolower($type)).'!</span>';
	}
}
function checkV($add, $ver){
	if(!checkB($add))
		return False;
	return version_compare(getV($add),$ver,">=");
}
function getV($add){
	$data = array(
		'php' => 'phpversion',
		'libxml' => LIBXML_DOTTED_VERSION,
		'SQLite' => 'sqlite_libversion',
		'sqlite3' => 'SQLite3::version'
	);	
	if(!checkB($add))
		return False;
	if(is_callable($data[$add])){
		$x = call_user_func($data[$add]);
		if(is_array($x) && count($x)>=1){
			$x = array_values($x);
			return $x[0];
		}else
			return $x;
	}
	return $data[$add];
}
function checkB($add){
	if($add === 'php')
		return True;
	return extension_loaded($add);
}
?>